<template>
  <div>

    <el-dialog title="短信模版设置" :visible.sync="dialogVisible" :close-on-click-modal="false" width="500px" @close="close" append-to-body>
      <div class="form-box new_form_box">
        <el-form ref="formAdd" :model="form" :inline="true" :rules="rules" label-width="80px" class="demo-ruleForm">
          <el-form-item label="验证码" prop="yzmCode">
            <el-input v-model="form.yzmCode" placeholder="请输入验证码模板ID" />
          </el-form-item>
          <el-form-item label="提醒上线" prop="sxCode">
            <el-input v-model="form.sxCode" placeholder="请输入提醒上线模板ID" />
          </el-form-item>
          <el-form-item  label="提醒付款" prop="fkCode" >
            <el-input v-model="form.fkCode"  placeholder="请输入提醒付款模板ID"  />
          </el-form-item>
          <div class="center">
            <el-button @click="clearList()" v-if="this.settingId" type="danger">删除</el-button>
            <el-button @click="close()">取消</el-button>
            <el-button type="primary" @click="submitForm('formAdd')" v-loading="loading">提交</el-button>
          </div>
        </el-form>
      </div>
    </el-dialog>
  </div>

</template>

<script>
import {
  addtenantPushSettings,
  getTenantPushSettingsByTenantId,
  delTenantPushSettings,
} from "@/api/system/shopManage";

export default {
  name: "",
  data() {
 
    return {
      dialogVisible: false,
      loading: false,
      // 表单参数
      form: {
        yzmCode: "",
        sxCode: "",
        fkCode: ""
      },
      rules: {
       
      },
      tenantInfo: "",
      settingId: "",
    };
  },
  created() {},
  methods: {
    // 打开弹窗
    open(tenantInfo) {
      this.tenantInfo = tenantInfo;
      this.dialogVisible = true;
      this.getList();
    },
    // 获取
    getList() {
      this.tableData = [];
      getTenantPushSettingsByTenantId({
        tenantId: this.tenantInfo.tenantId,
        type: 5, //4 短信模板ID设置
      }).then((res) => {
        if (res.data && res.data.settingsJson) {
          this.settingId = res.data.id;
          this.form = JSON.parse(res.data.settingsJson);
        }
      });
    },

    // 清空配置
    clearList() {
      delTenantPushSettings(this.settingId).then((res) => {
        this.$message.success(res.msg);
        this.dialogVisible = false
      });
    },
    // 保存到后台
    save() {
      addtenantPushSettings({
        tenantId: this.tenantInfo.tenantId,
        tenantName: this.tenantInfo.tenantName,
        settingsJson: JSON.stringify(this.form),
        type: 5,
      }).then((res) => {
        this.$message.success(res.msg);
        this.dialogVisible = false;
      });
    },

    // 重置
    reset() {
      this.$refs.formAdd.resetFields();
    },

    /** 查询详情进行回显 */
    handleUpdate(row) {
      this.form = row;
    },
    submitForm(formName) {
      this.$refs["" + formName].validate((valid) => {
        if (valid) {
          this.save();
        } else {
          this.$alert("请填写完整！");
        }
      });
    },

    close() {
      this.reset()
      this.dialogVisible = false;
    },
  },
};
</script>
<style scoped lang="css">

</style>
